//
//  WYRedPacketListCell.m
//  Boss
//
//  Created by admin on 2018/6/7.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYRedPacketListCell.h"
#import "WYUserMessage.h"
@interface WYRedPacketListCell()

@property (strong, nonatomic) IBOutlet UIImageView *userImageView;

@property (strong, nonatomic) IBOutlet UILabel *userName;
@property (strong, nonatomic) IBOutlet UILabel *timeLabel;
@property (strong, nonatomic) IBOutlet UILabel *moneyLabel;

@property (strong, nonatomic) IBOutlet UIImageView *bestImageView;
@property (strong, nonatomic) IBOutlet UILabel *bestLabel;
@property (strong, nonatomic) IBOutlet UIImageView *vipImageView;


@end
@implementation WYRedPacketListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [self.userImageView setCornerRadius:20.f];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setMessage:(WYReceivePeopleMessage *)message
{
    _message = message;
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:message.userPhoto] placeholderImage:[UIImage imageNamed:@"ic_defult_avatar"]];
    self.timeLabel.text = [NSString compareTimeWithBossTime:message.receiveDate];
    self.userName.text = message.userName;
//    self.moneyLabel.text = [NSString stringWithFormat:@"%.3f元",message.receiveAmount.floatValue/1000.0];
    self.moneyLabel.text = [self formatFloat:message.receiveAmount.floatValue/1000.0];
    if (message.best.intValue) {
        self.bestImageView.hidden = NO;
        self.bestLabel.hidden = NO;
    }else{
        self.bestImageView.hidden = YES;
        self.bestLabel.hidden = YES;
    }
    
    [self.vipImageView showVipImageViewStatusWithVipId:message.userVipLevel];
    
    
}
-(void)setList:(WYMYReceiveList *)list
{
    _list = list;
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:list.userPhoto] placeholderImage:[UIImage imageNamed:@"ic_defult_avatar"]];
    self.timeLabel.text = [NSString compareTimeWithBossTime:list.receiveDate];
    self.userName.text = list.userName;
//     self.moneyLabel.text = [NSString stringWithFormat:@"%.3f元",list.receiveAmount.floatValue/1000.0];
    self.moneyLabel.text = [self formatFloat:list.receiveAmount.floatValue/1000.0];
    if (list.best.intValue) {
        self.bestImageView.hidden = NO;
        self.bestLabel.hidden = NO;
    }else{
        self.bestImageView.hidden = YES;
        self.bestLabel.hidden = YES;
    }
    [self.vipImageView showVipImageViewStatusWithVipId:list.userVipLevel];
}
-(void)setRedList:(WYSendRedPacketList *)redList
{
    _redList = redList;
    
//    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:list.userPhoto] placeholderImage:nil];
    self.timeLabel.text = [NSString compareTimeWithBossTime:redList.createTime];
//    self.userName.text = redList.userName;
//    self.moneyLabel.text = [NSString stringWithFormat:@"%.3f元",redList.money.floatValue/1000.0];
//    self.moneyLabel.text = [self formatFloat:redList.money.floatValue/1000.0];
    self.moneyLabel.text = [self formatFloat:redList.money.floatValue/1000.0];
    if (redList.state.intValue) {
        self.bestImageView.hidden = YES;
        self.bestLabel.hidden = NO;
        self.bestLabel.text = @"已领完";
        self.bestLabel.textColor = kColor999999;
    }else{
        self.bestImageView.hidden = YES;
        self.bestLabel.hidden = NO;
         self.bestLabel.text = @"未领完";
        self.bestLabel.textColor = [UIColor hexStringToColor:@"#FFC066" alpha:1.0];
    }
    WYUserMessage *userMessage = [WYStoreModule currentUserMessage];
    
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:userMessage.url] placeholderImage:[UIImage imageNamed:@"ic_defult_avatar"]];
    self.userName.text = userMessage.userName;
    [self.vipImageView showVipImageViewStatusWithVipId:userMessage.vipId];
    
}
-(void)setTime:(WYInviteTime *)time
{
    _time = time;
    self.bestImageView.hidden = YES;
    self.bestLabel.hidden = YES;
    [self.vipImageView showVipImageViewStatusWithVipId:time.vipId];
    self.timeLabel.text = [NSString stringWithFormat:@"%@ 加入",time.inviteTime];
    //    self.userName.text = redList.userName;
//    self.moneyLabel.text = [NSString stringWithFormat:@"%.3f元",time.amount.floatValue/1000.0];
    self.moneyLabel.text = [self formatFloat:time.amount.floatValue/1000.0];
    self.userName.text = time.userName;
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:time.url] placeholderImage:[UIImage imageNamed:@"ic_defult_avatar"]];
}
- (NSString *)formatFloat:(float)f
{
    if (fmodf(f, 1)==0) {//如果有一位小数点
        return [NSString stringWithFormat:@"%.2f元",f];
    } else if (fmodf(f*10, 1)==0) {//如果有两位小数点
        return [NSString stringWithFormat:@"%.2f元",f];
    } else if(fmod(f*100, 1)==0){
        return [NSString stringWithFormat:@"%.2f元",f];
    }else{
        return [NSString stringWithFormat:@"%.3f元",f];
    }
}
@end
